<template>
  <a-drawer
    title="启动文档签审"
    :width="'580px'"
    :visible="processDrawVisible"
    :allowClear="true"
    :maskClosable="false"
    :body-style="{ paddingBottom: '80px', paddingTop: '16px' }"
    @close="onClose"
  >
    <div class="selectBox">
      <!-- <process :formData="formData" @selectOptions="selectOptions"></process> -->
      <commonProcessSettings
        ref="commonProcessSettings"
        :stateType="'startProjact'"
        :formData="formData"
        @fields='fields'
      ></commonProcessSettings>
    </div>
    <div
      :style="{
        position: 'absolute',
        right: 0,
        bottom: 0,
        width: '100%',
        borderTop: '1px solid #e9e9e9',
        padding: '10px 16px',
        background: '#fff',
        textAlign: 'right',
        zIndex: 1,
      }"
    >
      <a-button :style="{ marginRight: '8px' }" @click="onClose">
        取消
      </a-button>
      <a-button type="primary" :loading="drawLoading" @click="confirm">
        确定
      </a-button>
    </div>
  </a-drawer>
</template>
<script>
import commonProcessSettings from '@/components/common/commonProcessSettings'
import { getWFSelectPrincipal, startDocWfProcess } from "@/apiTest/fileApi.js"
export default {
  name: "processDraw",
  components: {
    commonProcessSettings,
  },
  props: ['processDrawVisible'],
  data() {
    return {
      formData: [],
      // fileSingleDataC: JSON.parse(sessionStorage.getItem('fileSingleDataByStart')).tableArr[0]['oid'],
      drawLoading: false
    };
  },
  watch: {
    processDrawVisible(val) {
      if (val) {
        this.initData()
      }
    }
  },
  computed: {},
  mounted() {},
  methods: {
    initData() {
      this.getProcess()
    },
    onClose() {
      this.$emit('drawClose')
    },
    confirm() {
      this.$refs.commonProcessSettings.handleChange()
      // this.$emit('drawConfirm')
    },
    /**
     * commonProcessSettings 组件回调方法
     * 功能： 提交
     */
    fields(val) {
      let data = {
        oids: [], 
        processTemplate: 'WF_Document', 
        processUsers: JSON.stringify(val), 
        processState: ''
      }
      // this.tableData.forEach((e)=>{
        // data.oids.push(e.oid)
      // })
      data.oids.push(JSON.parse(sessionStorage.getItem('fileTableItem'))[0].oid)
      data.oids = JSON.stringify(data.oids)
      startDocWfProcess(data).then((res) => {
        if (res && res.data.success) {
          this.$message.success('提交成功');
          //跳转至文件树，并关闭文档签审页面
          // let tabArrNew = JSON.parse(sessionStorage.getItem('tabArr'))
          // tabArrNew = tabArrNew.filter((rec) => {
          //   return rec.title !== '文档签审' && rec.title !== '查看交付物'
          // })
          // this.$store.commit('SET_TABS', tabArrNew)
          // this.$router.push('/single/fileSingle');
          this.$emit('drawConfirm')
        } else {
          this.$message.error(res.data.message)
        }
      })
    },

    /** *获取流程人 */
    getProcess() {
      this.formData = []
      getWFSelectPrincipal({
        "oid": JSON.parse(sessionStorage.getItem('fileTableItem'))[0].oid,
        "processName": "WF_Document",
      }).then((res) => {
        if (res && res.data.success) {
          //每个下拉菜单的值
          let optionUser = []
          optionUser = res.data.data[0].selectedUsers
          res.data.data.forEach((item, index) => {
            if (index === 0) return
            //下拉框默认显示的值
            let initUser = []
            initUser = item.initUsers && item.initUsers.map((rec) => {
              return rec.fullname
            })
            this.formData.push({
              name: item.name,
              oid: item.oid,
              required: item.required,
              selsectData: optionUser,
              checkSelsectData: initUser
            })
          })
        } else {
          this.$message.error(res.data.message)
        }
      })
    },


  },
};
</script>
<style lang="less" scoped>
.selectBox {
  /deep/ .ant-form .ant-form-item {
    display: block;
    .ant-form-item-label {
      line-height: normal;
    }
    .ant-form-item-control-wrapper {
      .ant-form-item-control {
        .ant-form-item-children {
          .ant-select-enabled {
            width: 100% !important;
          }
        }
      }
    }
  }
}
</style>